package com.system.manager.modules.authorized.controller;


import com.system.manager.common.annotation.PreAuthorize;
import com.system.manager.common.entity.Result;
import com.system.manager.common.entity.ResultLayUI;
import com.system.manager.common.enums.ErrorCode;
import com.system.manager.modules.authorized.entity.Role;
import com.system.manager.modules.authorized.enums.SubjectType;
import com.system.manager.modules.authorized.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yxp
 * @since 2021-10-18
 */
@Api(tags = "角色API")
@RestController
@RequestMapping("/role/")
public class RoleController {

    @Autowired
    private IRoleService roleService;

    @ApiOperation("获取所有的角色")
    @PreAuthorize(SubjectType.SYSTEM_ADMIN)
    @GetMapping("list")
    public Result roleList(){
        try{
            // 获取所有的角色
            List<Role> list = roleService.list();

            return Result.ok(list);

        }catch (Exception e){
            e.printStackTrace();
            // 查询数据库出现异常
            return Result.error();
        }


    }
}
